<?php
/**
 * Created by PhpStorm.
 * User: 小蛮哼哼哼
 * Email: 243194993@qq.com
 * Date: 2022/6/28
 * Time: 9:33
 * motto: 现在的努力是为了小时候吹过的牛逼！
 */

declare(strict_types=1);

namespace app\admin\controller\system;

use app\common\controller\AdminController;
use app\common\lib\ArrClass;
use app\common\lib\Show;
use app\common\lib\Status;

class Address extends AdminController
{
    /**
     * @return array|\think\response\Json
     * @throws \ReflectionException
     * @throws \think\Exception
     */
    public function getShopByAddress()
    {
        $keywords = $this->request->param('keywords', '', 'trim');
        $city = $this->request->param('city', '', 'trim');
        if (empty($keywords)) {
            return Show::json_show(Status::mini_error, "请输入搜索词");
        }
        $type = sysconfig('map', 'map_type');
        $key_id = sysconfig('map', 'map_local_key_id');

        $key = ArrClass::mapAttr();
        $obj = ArrClass::initClass($type, $key, [$key_id], true);
        $result = $obj->suggestion($keywords, $city);
        if ($result['code'] == Status::status_normal) {
            return Show::json_show(Status::status_normal, "ok", $result['data']);
        } else {
            return Show::json_show(Status::status_error, $result['msg']);
        }
    }
}